<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
	<head> 
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <c:set value="<%=ResourcesUtil.getConfig(\"payroll_type_base_pay\")%>" var="basePay" />
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <script>
    var pBasePay = "${basePay}";

   $(document).ready(function(){
		
        // 下拉选框带搜索功能
        $("#sex").select2();
        $("#ognizationId").select2();
        $("#roleId").select2();
        $("#dutyId").select2();
        $("#groupId").select2();
        $("#payrollType").select2();
        selectPayRollType();
	}); 
    
    $(function(){
        var form = $("#inputForm");  
        form.validate();//验证指定的表单
        $("#confirmBtn").click(function(){
        	if (form.valid()) {//如果表单验证成功，则进行提交。  
            $("#showHtml").addClass("showHtml");
            $("#confirmPage").css("display","block");
            $("#editPage").css("display","none");
            $("#birthDate").removeClass("laydate-icon");
            $('.showHtml').find('input,select,textarea').attr('disabled',true);
            return false;
        	}
         });
    });


    //保存方法
    var saveForm={
         t:null,
         save:function(t){
             $(t).attr("disabled",true);
             this.t=t;
          	 // 格式化，去除逗号
             formUnFormat($("#inputForm"));
             $('.showHtml').find('input,select,textarea').attr('disabled',false);
      	     var params = $("#inputForm").serialize();
             $.post("${ctx}/companyuser/message/save",params,function(result){
            	 // 提示信息
                 tipParent(result.message);
                 // 返回状态
                 if(result.statusCode==STATUSCODEOK){
                    // 刷新页面
                    window.parent.frames[0].searchListForm();
                    closeWin(); 
                 }else{
                      $(saveForm.t).attr("disabled",false);
                 }
             },'json');
         } 
    }
    
    // 基本工资选择，工资入力框制御
    function selectPayRollType(){
    	if(pBasePay==$("#payrollType").val()){
    		$('#payrollSum').attr("disabled",false); 
    	}else{
    		$('#payrollSum').attr("disabled",true); 
    		$('#payrollSum').val('');
    	}
    }
    </script> 
    
    </head>
	<body>
	<!-- 创建页面head部 -->
	<div id="editPage" class="layerHeader clearfix">
	
		<c:choose>
	        <c:when test="${companyUser.id!=null && companyUser.id!=''}">
	             <!-- 修改编辑 -->
	            <p class="headerTitle"><spring:message code="CompanyUser_head_edit_info"/></p>
	        </c:when>
	        <c:otherwise>
	             <!-- 新建 -->
	            <p class="headerTitle"><spring:message code="CompanyUser_head_create_info"/></p>
	        </c:otherwise>
	    </c:choose>

	    <div class="headerButton clearfix">
	       <button type="button" id="confirmBtn"><spring:message code="btn_ok"/></button>
	       <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	
	<!-- 确认页面head部 -->
	<div id="confirmPage" class="layerHeader clearfix" style="display:none">
		<p class="headerTitle"><spring:message code="CompanyUser_head_confirm_info"/></p>
	    <div class="headerButton clearfix">
	        <shiro:hasPermission name="companyuser:message:edit">
	        <button type="button" id="saveBtn" onclick="saveForm.save(this)"><spring:message code="common_save"/></button>
 			</shiro:hasPermission>
	        <button type="button" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
	    </div>
	</div>
	
	
	<div class="tabBox">
    <ul class="clearfix">
        <li class="active">员工信息</li>
    </ul>
    </div>
    <form id="inputForm" method="post" >
    <c:set value="<%=ResourcesUtil.getConfig(\"SEX\")%>" var="customerLevel" />
    <c:set value="<%=ResourcesUtil.getConfig(\"payroll_type\")%>" var="userPayRollType" />
    <input type="hidden" id="id" name="id" value="${companyUser.id}"/>
    <input type="hidden" id="comUserName" name="comUserName" value="${companyUser.comUserName}"/>
<div id="showHtml">
	<div class="smList">
	        <div class="items clearfix">
	        	<div class="col-50 clearfix haveToBox">
	        		<!--公司名称-->
	                <p class="tit"><spring:message code="CompanyUser_Company" /></p>
	                <select  style="width:43%" id="ognizationId"  name="ognizationId" data-rule-required="true"   data-msg-required="<spring:message code="CompanyUser_err_msg_ognizationName"/>">
                       <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
                       <c:forEach items="${companyOgnizationTemp.ognizationList}" var="company" varStatus="status">
                       <option value="${company.ognizationId}" <c:if test="${companyUser.ognizationUserId eq companyUser.id   && company.ognizationId eq companyUser.ognizationUser}">selected="selected"</c:if >>${company.ognizationName} </option>
                       </c:forEach>
                    </select> 
                    <p class="haveTo">*</p>
	            </div>
	            
	            <div class="col-50 right clearfix haveToBox">
	            	<!--人员角色-->
	                <p class="tit"><spring:message code="CompanyUser_RoleAll" /></p>
	                <select style="width:43%" id="roleId"  name="roleId" data-rule-required="true"   data-msg-required="<spring:message code="CompanyUser_err_msg_roleName"/>">
		                <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
		                <c:forEach items="${companyRoleTemp.roleList}" var="company" varStatus="status">
	                       <option value="${company.roleId}" <c:if test="${companyUser.loginUserId eq companyUser.id   && company.roleId eq companyUser.userRoleUserId}">selected="selected"</c:if >>${company.roleName} </option>
	                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
	            </div>
	        </div>
	        
	        <div class="items clearfix haveToBox">
	        	<div class="col-50 clearfix">
	        		<!--人员职务-->
	                <p class="tit"><spring:message code="CompanyUser_DutyAll" /></p>
	                <select style="width:43%" id="dutyId"  name="dutyId" data-rule-required="true"   data-msg-required="<spring:message code="CompanyUser_err_msg_dutyName"/>">
		                <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
		                <c:forEach items="${companyUserTemp.userList}" var="company" varStatus="status">
	                       <option value="${company.dutyId}" <c:if test="${companyUser.ognizationUserId eq companyUser.id   && company.dutyId eq companyUser.ognizationDutyId}">selected="selected"</c:if >>${company.dutyName} </option>
	                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
	            </div>
	            
	            <div class="col-50 right clearfix haveToBox">
	            	<!--人员组别-->
	                <p class="tit"><spring:message code="CompanyUser_GroupAll" /></p>
	                <select style="width:43%" id="groupId"  name="groupId" data-rule-required="true"   data-msg-required="<spring:message code="CompanyUser_err_msg_groupName"/>">
		                <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
		                <c:forEach items="${companyGroupTemp.groupList}" var="company" varStatus="status">
	                       <option value="${company.groupId}" <c:if test="${companyUser.groupUserId eq companyUser.id   && company.groupId eq companyUser.groupUserGroupId}">selected="selected"</c:if >>${company.groupName} </option>
	                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix haveToBox">
	        		<!--姓-->
	                <p class="tit"><spring:message code="CompanyUser_firstname" /></p>
	                <input id="firstNameEn" name="firstNameEn" value="${companyUser.firstNameEn}" data-rule-required="true" data-msg-required="<spring:message code="CompanyUser_err_msg_firstName"/>">
	                <p class="haveTo">*</p>
	            </div>
	            
	            <div class="col-50 right clearfix haveToBox">
	            	<!--名字-->
	                <p class="tit"><spring:message code="CompanyUser_Lastname" /></p>
	                <input id="lastNameEn" name="lastNameEn" value="${companyUser.lastNameEn}" data-rule-required="true" data-msg-required="<spring:message code="CompanyUser_err_msg_lastName"/>">
	                <p class="haveTo">*</p>
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix haveToBox">
	        		<!--登录名-->
	                <p class="tit"><spring:message code="CompanyUser_loginname" /></p>
	                <input id="loginName" name="loginName" value="${companyUser.loginName}" data-rule-required="true" data-msg-required="<spring:message code="CompanyUser_err_msg_loginName"/>">
	            	<p class="haveTo">*</p>
	            </div>
	            <c:if test="${companyUser.editFlag == 0}">
	            <div class="col-50 right clearfix haveToBox">  
	            	<!--密码-->  
	                <p class="tit"><spring:message code="CompanyUser_password" /></p>
	                <input id="password" name="password" value="${companyUser.password}" data-rule-required="true" data-msg-required="<spring:message code="CompanyUser_err_msg_password"/>">
	            	<p class="haveTo">*</p>
	            </div>
	            </c:if>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix haveToBox">
	        		<!--性别-->
	                <p class="tit"><spring:message code="CompanyUser_Sex" /></p>
	                <c:set value="SEX" var="companyUserList" />      
	                <select style="width:43%" id="sex" name="sex" data-rule-required="true" data-msg-required="<spring:message code="CompanyUser_err_msg_sex"/>" >
                      <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
	                  <%-- <c:forEach items="${sexList}" var="item">
								<option value="${item.itemCode}-${item.itemValue}">selected="selected"${item.itemName}</option>
					  </c:forEach> --%>
					  <c:forEach items="${fns:getDictList(companyUserList)}" var="item">
                        <option value="${item.itemCode}-${item.itemValue}" <c:if test="${fn:split(companyUser.sex,'-')[1] eq item.itemValue }">selected="selected"</c:if>>${item.itemName}</option>
                      </c:forEach>
                    
                    </select>
                    <p class="haveTo">*</p>
	            </div>
	                
	            <div class="col-50 right clearfix">
	            	<!--出生年月-->
	                <p class="tit"><spring:message code="CompanyUser_BirthDate" /></p>
	                <div class="timeBox">
							<input type="text" onblur="CheckDate(this);" 
								id="birthDate" name="birthDate" style="width: 150px" value="<fmt:formatDate value="${companyUser.birthDate}" pattern="yyyy-MM-dd" />">
				    </div>
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--联系电话-->
	                <p class="tit"><spring:message code="CompanyUser_telNo" /></p>
	                <%-- <input id="mobile" name="mobile" onkeyup="this.value=this.value.replace(/[^0-9-]+/,'');" value="${companyUser.mobile}"> --%>
	            	<input id="mobile" name="mobile"  value="${companyUser.mobile}">	            
	            </div>
	            <div class="col-50 right clearfix">
	            	<!--身份证号-->
	                <p class="tit"><spring:message code="CompanyUser_MobileNo" /></p>
	                <input id="idientityCardNumber" name="idientityCardNumber"  value="${companyUser.idientityCardNumber}">
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--传真-->
	                <p class="tit"><spring:message code="CompanyUser_faxNo" /></p>
	                 <input id="faxNo" name="faxNo" value="${companyUser.faxNo}">
	            </div>
	            
	            <div class="col-50 right clearfix">
	            	<!--Email-->
	                <p class="tit"><spring:message code="CompanyUser_Email" /></p>
	                <input id="email" name="email" value="${companyUser.email}" data-rule-email="true"  data-msg-email="<spring:message code="user_saveEmail"/>">
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--国别-->
	                <p class="tit"><spring:message code="CompanyUser_country" /></p>
	                <input id="country" name="country" value="${companyUser.country}">
	            </div>
	            
	            <div class="col-50 right clearfix">
	            	<!--城市-->
	                <p class="tit"><spring:message code="CompanyUser_city" /></p>
	                <input id="city" name="city" value="${companyUser.city}">
	            </div>
	        </div>
	        
	        <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--工资类别-->
	                <p class="tit"><spring:message code="CompanyUser_payrollType" /></p>
	                <select style="width:43%" id="payrollType" name="payrollType" onchange="selectPayRollType();">
	                   <option value="" selected = "selected"><spring:message code="CompanyUser_pleaseChoose"/></option>
                       <c:forEach items="${fns:getDictList(userPayRollType)}" var="payRoll">
                           <option <c:if test="${fn:split(companyUser.payrollType,'-')[1] eq payRoll.itemValue}">selected="selected"</c:if> value="${payRoll.itemCode}-${payRoll.itemValue}">
                                 ${payRoll.itemName}
                           </option>
                       </c:forEach>                    
                    </select>
	            </div>
	            
	            <div class="col-50 right clearfix">
	            	<!--工资-->
	                <p class="tit"><spring:message code="CompanyUser_payrollSum" /></p>
	                <input type="tel" id="payrollSum" name="payrollSum" value="<fmt:formatNumber value="${companyUser.payrollSum}" pattern="#,#00.00#"/>" disabled="true" onblur="formatNumber(this)" onfocus="unFormat(this)">
	            </div>
	        </div>

			<div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--详细住址-->
	                <p class="tit"><spring:message code="CompanyUser_addressAll" /></p>  
	                <textarea id="address" name="address" value="${companyUser.address}" style="width:200px;height:40px;">${companyUser.address}</textarea>
	            </div>
	        </div>
	        
            <div class="items clearfix">
	        	<div class="col-50 clearfix">
	        		<!--备注-->
	                <p class="tit"><spring:message code="CompanyUser_remarks" /></p>
	                <textarea id="remarks" name="remarks" value="${companyUser.remarks}" style="width:200px;height:40px;">${companyUser.remarks}</textarea>
	            </div>
	        </div>
	</div>
</div>
</form>
</body>
</html>
